import { BaseWindow } from "../../../../component/window/BaseWindow";
import { IStallOtherStallWindow } from "../interfaces/IStallOtherStallWindow";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { SellItemCellRenderer } from "../cell/SellItemCellRenderer";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { PriceItem } from "../cell/PriceItem";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { MsgManager } from "../../../manager/MsgManager";
import { ItemData } from "../../../resource/info/ItemData";
import { BuyWindow } from "./BuyWindow";
import { SPublicMiniPlayer } from "../../../../../Message/Public/SPublicMiniPlayer";
import { PlayerMiniInfo } from "../../../model/PlayerMiniInfo";
import { IDragDrop } from "../../../../../com/mui/manager/IDragDrop";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class OtherStallWindow
    
    export  class OtherStallWindow extends BaseWindow implements IStallOtherStallWindow
    {
        constructor()
        {
            super();
            titleHeight = 30;
            setSize(367, 416);
            title = Language.getString(40837);
            this.initView();
            this.addListeners();
            return;
        }

        /* internal  */initView(): void
        {
            this.initBg();
            this.initTop();
            this.initMiddle();
            this.initBottom();
            return;
        }

        /* internal  */initBg(): void
        {
            ObjCreate.createBg(17, 41, 333, 306, this);
            return;
        }

        /* internal  */initTop(): void
        {
            this._nameInput = ObjCreate.createGTextInput(16, 46, 322, 20, this);
            this._nameInput.editable = false;
            this._nameInput.maxChars = 10;
            return;
        }

        /* internal  */initMiddle(): void
        {
            this._itemTileList = new GTileList();
            this._itemTileList.setSize(325, 244);
            this._itemTileList.rowHeight = 38;
            this._itemTileList.columnWidth = 158;
            this._itemTileList.horizontalGap = 5;
            this._itemTileList.verticalGap = 3;
            this._itemTileList.setStyle("skin", new Object /* flash.display.Bitmap */());
            this._itemTileList.setStyle("cellRenderer", SellItemCellRenderer);
            this._itemTileList.x = 22;
            this._itemTileList.y = 75;
            this._itemTileList.dataProvider = new DataProvider(new Array<any>(null, null, null, null, null, null, null, null, null, null, null, null));
            this.addChild(this._itemTileList);
            this._itemTileList.validateNow();
            return;
        }

        /* internal  */initBottom(): void
        {
            var loc1=ObjCreate.createTextField(Language.getString(40838), 60, 355, 60, 20, this);
            this._itemMoney = new PriceItem();
            this._itemMoney.goldLength = 58;
            this._itemMoney.coinLength = 58;
            this._itemMoney.x = 125;
            this._itemMoney.y = 355;
            this.addChild(this._itemMoney);
            this._btnBoothMessage = ObjCreate.createGButton(Language.getString(40839), 25, 379, 70, 26, this);
            this._btnChatHost = ObjCreate.createGButton(Language.getString(40840), 106, 379, 70, 26, this);
            this._btnAddFriend = ObjCreate.createGButton(Language.getString(40841), 190, 379, 70, 26, this);
            this._btnBuy = ObjCreate.createGButton(Language.getString(40842), 274, 379, 70, 26, this);
            return;
        }

        /* internal  */addListeners(): void
        {
            this._btnBuy.addEventListener(flash.events.MouseEvent.CLICK, this.BuyHandler);
            this._btnBoothMessage.addEventListener(flash.events.MouseEvent.CLICK, this.ShowOrHideBoothHandler);
            this._btnChatHost.addEventListener(flash.events.MouseEvent.CLICK, this.onChatHost);
            this._btnAddFriend.addEventListener(flash.events.MouseEvent.CLICK, this.onAddFriend);
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            super.createDisposedChildrenImpl();
            _closeBtn.configEventListener(flash.events.MouseEvent.CLICK, this.closeHandler, false, 9999);
            return;
        }

        /* internal  */onChatHost(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ChatPrivate, this._playerInfo));
            return;
        }

        /* internal  */onAddFriend(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.FriendRequestAddFriend, {"name": this._playerInfo.playerName}));
            return;
        }

        /* internal  */BuyHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._itemTileList.selectedIndex < 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(40843));
                return;
            }
            var loc1=this._itemTileList.dataProvider.getItemAt(this._itemTileList.selectedIndex) as ItemData;
            if (!loc1) 
            {
                MsgManager.showRollTipsMsg(Language.getString(40843));
                return;
            }
            var loc2=BuyWindow.getInstance();
            loc2.data = loc1;
            loc2.show();
            return;
        }

        /* internal  */ShowOrHideBoothHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.StallShowOrHideOtherBoothMsg));
            return;
        }

        /* internal  */closeHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.StallCloseStall));
            return;
        }

        public refreshItemList(arg1: Array<any>): void
        {
            if (arg1 && arg1.length > 0) 
            {
                this._itemTileList.dataProvider = new DataProvider(arg1);
            }
            else 
            {
                this._itemTileList.dataProvider = new DataProvider([null, null, null, null, null, null, null, null, null, null, null, null]);
            }
            return;
        }

        public refreshPetMountsList(): void
        {
            return;
        }

        public refreshBoothName(arg1: string): void
        {
            this._nameInput.text = arg1;
            return;
        }

        public updateMoney(arg1: int, arg2: int): void
        {
            this._itemMoney.updateCoin(arg1);
            this._itemMoney.updateGold(arg2);
            return;
        }

        public set playerMiniInfo(arg1: SPublicMiniPlayer)
        {
            if (this._playerInfo) 
            {
                this._playerInfo.miniPlayer = arg1;
            }
            else 
            {
                this._playerInfo = new PlayerMiniInfo(arg1);
            }
            title = ObjCreate.createTitleTextField(Language.getStringByParam(40844, arg1.name));
            return;
        }

        public /* override */ canDrop(arg1: IDragDrop, arg2: IDragDrop): Boolean
        {
            return false;
        }

        /* internal */ /* var */_nameInput: GTextInput;

        /* internal */ /* var */_btnBoothMessage: GButton;

        /* internal */ /* var */_btnChatHost: GButton;

        /* internal */ /* var */_btnAddFriend: GButton;

        /* internal */ /* var */_itemTileList: GTileList;

        /* internal */ /* var */_btnBuy: GButton;

        /* internal */ /* var */_btnCancel: GButton;

        /* internal */ /* var */_itemMoney: PriceItem;

        /* internal */ /* var */_playerInfo: PlayerMiniInfo;
    }
